package com.huawei.gamebox.service.welfare.campaign.node;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.huawei.appgallery.foundation.ui.framework.widget.Space;
import com.huawei.gamebox.service.common.cardkit.card.BaseGsCard;
import com.huawei.gamebox.service.welfare.campaign.card.BaseCampaignCard;
import com.huawei.gamebox.service.welfare.common.card.AbsWithTitleCard;
import o.azb;
import o.chy;
import o.Logger;
import o.exp$a;
import o.exp$f;
import o.exp.d;
import o.fbt;

public abstract class BaseCampaignColumnNode extends BaseCampaignWithTitleNode {
    private int ʻ = -1;
    private int ᐝ = -1;

    class b implements OnClickListener {
        private BaseGsCard ˋ;
        final /* synthetic */ BaseCampaignColumnNode ˎ;

        b(BaseCampaignColumnNode baseCampaignColumnNode, BaseGsCard baseGsCard) {
            this.ˎ = baseCampaignColumnNode;
            this.ˋ = baseGsCard;
        }

        public void onClick(View view) {
            this.ˎ.ˊ.ˏ(0, this.ˋ);
        }
    }

    public BaseCampaignColumnNode(Context context) {
        super(context);
    }

    protected void ॱ(int i, int i2, int i3) {
        this.ʻ = i;
        this.ᐝ = i2;
        if (Logger.ˎ()) {
            Logger.ˏ("BaseCampaignColumnNode", "defaultColumnSize_:" + i3);
        }
        this.ˋ = (int) this.ॱ.getResources().getDimension(exp$a.ˊˊ);
    }

    protected BaseCampaignCard ˏ(boolean z) {
        return new fbt(this.ॱ, z);
    }

    protected View ˎ() {
        ViewGroup viewGroup = (ViewGroup) super.ˎ();
        LayoutParams layoutParams = (LayoutParams) ((LinearLayout) viewGroup.findViewById(d.ˎ)).getLayoutParams();
        if (layoutParams != null) {
            layoutParams.bottomMargin = this.ॱ.getResources().getDimensionPixelSize(exp$a.ʽॱ);
        }
        ((TextView) viewGroup.findViewById(d.ᶥ)).setText(this.ॱ.getText(exp$f.ᐝॱ));
        return viewGroup;
    }

    protected void ˏ(AbsWithTitleCard absWithTitleCard, int i, int i2) {
        absWithTitleCard.ˋ();
        ViewGroup.LayoutParams layoutParams = new LayoutParams(-2, -2);
        LayoutInflater from = LayoutInflater.from(this.ॱ);
        View linearLayout = new LinearLayout(this.ॱ);
        View ˉ = absWithTitleCard.ˉ();
        if (ˉ instanceof ViewGroup) {
            ((ViewGroup) ˉ).removeAllViews();
            ((ViewGroup) ˉ).addView(linearLayout, layoutParams);
        }
        linearLayout.setOrientation(0);
        int ᐝ = ᐝ();
        linearLayout.setPadding(ᐝ, this.ॱ.getResources().getDimensionPixelSize(exp$a.ʽॱ), ᐝ, 0);
        ᐝ = ᐝॱ();
        if (i > ᐝ) {
            i = ᐝ;
        }
        int ˋ = ˋ(ᐝ);
        for (int i3 = 0; i3 < i; i3++) {
            BaseGsCard ˏ;
            ViewGroup viewGroup = (ViewGroup) from.inflate(ʼ(), null);
            ॱ(viewGroup, ˋ);
            if (i3 == i - 1) {
                ˏ = ˏ(true);
                linearLayout.addView(viewGroup, layoutParams);
            } else {
                ˏ = ˏ(false);
                linearLayout.addView(viewGroup, layoutParams);
                View spaceEx = new Space(this.ॱ);
                spaceEx.setLayoutParams(new LayoutParams(this.ˋ, -1));
                linearLayout.addView(spaceEx);
            }
            ˏ.ˏ(viewGroup);
            absWithTitleCard.ॱ(ˏ);
        }
        ˋ(this.ˊ);
    }

    private int ᐝॱ() {
        int ॱ = azb.ॱ(this.ॱ) - (ᐝ() * 2);
        int i = ॱ / this.ʻ;
        if (ॱ % this.ʻ >= this.ʻ / 2) {
            return i + 1;
        }
        return i;
    }

    private int ˋ(int i) {
        return ((azb.ॱ(this.ॱ) - (ᐝ() * 2)) - (this.ˋ * (i - 1))) / i;
    }

    private void ॱ(ViewGroup viewGroup, int i) {
        ((ImageView) viewGroup.findViewById(d.ꞌ)).setLayoutParams(new LayoutParams(i, (this.ᐝ * i) / this.ʻ));
        int dimensionPixelSize = i - (this.ॱ.getResources().getDimensionPixelSize(exp$a.ˊˋ) * 2);
        LinearLayout linearLayout = (LinearLayout) viewGroup.findViewById(d.ʻᐝ);
        ViewGroup.LayoutParams layoutParams = linearLayout.getLayoutParams();
        layoutParams.width = dimensionPixelSize;
        linearLayout.setLayoutParams(layoutParams);
    }

    public void ˋ(chy o_chy) {
        this.ˊ = o_chy;
        int ˊॱ = ˊॱ();
        for (int i = 0; i < ˊॱ; i++) {
            AbsWithTitleCard absWithTitleCard = (AbsWithTitleCard) ˊ(i);
            if (absWithTitleCard != null) {
                absWithTitleCard.ˊ().ॱ(o_chy);
                int ˎ = absWithTitleCard.ˎ();
                for (int i2 = 0; i2 < ˎ; i2++) {
                    BaseGsCard ˋ = absWithTitleCard.ˋ(i2);
                    if (ˋ != null) {
                        View ˉ = ˋ.ˉ();
                        if (ˉ instanceof ViewGroup) {
                            ((ImageView) ˉ.findViewById(d.ꞌ)).setOnClickListener(new b(this, ˋ));
                            ˉ.setOnClickListener(new b(this, ˋ));
                        }
                    }
                }
            }
        }
    }
}
